package com.elite.groovy.callback

import cn.com.tpUtil.GetXMLVB
import com.elite.groovy.util.EliteBean
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

public class apiAddPSTask implements ServiceBackInvoke{
	private static final Log log = LogFactory.getLog(apiAddPSTask.class);
	public String doCallBack(EliteBean eliteBean,HttpServletRequest request,HttpServletResponse response) {

		response.setCharacterEncoding("UTF-8");

		String getMethod = request.getMethod();
		log.debug("getMethod:" + getMethod);

		String inData = "";
		BufferedReader iny = null;
		if (getMethod.equals("GET")) {
			inData = request.getParameter("data");
			log.debug("原始Get请求参数:" + inData);
		} else {
			InputStreamReader reader = new InputStreamReader(request.getInputStream(), "UTF-8");
			iny = new BufferedReader(reader);
			String line;
			while ((line = iny.readLine()) != null) {
				inData += line;
			}
			log.debug("原始Post请求参数:" + inData);
		}

		def outData = "";

		try {
			//调用存储过程处理工单
			log.debug("调用存储过程处理处理数据...");

			def procedure = "{call Sp_P101(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
			def inputMap = new String[38];
			inputMap[0] = GetXMLVB.readStringXml(inData, "SYS_ID");
			inputMap[1] = GetXMLVB.readStringXml(inData, "SOURCE_TYPE");
			inputMap[2] = GetXMLVB.readStringXml(inData, "CHANNEL_TYPE");
			inputMap[3] = GetXMLVB.readStringXml(inData, "INSUR_CHANNEL_NAME");
			inputMap[4] = GetXMLVB.readStringXml(inData, "SALES_PERSON_ORGID");
			inputMap[5] = GetXMLVB.readStringXml(inData, "SALES_PERSON_ORGNAME");
			inputMap[6] = GetXMLVB.readStringXml(inData, "DATATYPE_ID");
			inputMap[7] = GetXMLVB.readStringXml(inData, "CAR_PLATE");
			inputMap[8] = GetXMLVB.readStringXml(inData, "IN_STARTDATE");
			inputMap[9] = GetXMLVB.readStringXml(inData, "OFFER_NO");
			inputMap[10] = GetXMLVB.readStringXml(inData, "QUOTE_NO");
			inputMap[11] = GetXMLVB.readStringXml(inData, "APPLICANT_NAME");
			inputMap[12] = GetXMLVB.readStringXml(inData, "INSURED_NAME");
			inputMap[13] = GetXMLVB.readStringXml(inData, "RISKCODE");
			inputMap[14] = GetXMLVB.readStringXml(inData, "SY_POLICY_NO");
			inputMap[15] = GetXMLVB.readStringXml(inData, "JQ_POLICY_NO");
			inputMap[16] = GetXMLVB.readStringXml(inData, "INSURANCESTATUS");
			inputMap[17] = GetXMLVB.readStringXml(inData, "STARTDATE");
			inputMap[18] = GetXMLVB.readStringXml(inData, "ENDDATE");
			inputMap[19] = GetXMLVB.readStringXml(inData, "BIZ_COST");
			inputMap[20] = GetXMLVB.readStringXml(inData, "JQX_COST");
			inputMap[21] = GetXMLVB.readStringXml(inData, "CARSHIPCOST");
			inputMap[22] = GetXMLVB.readStringXml(inData, "TRANSNAME");
			inputMap[23] = GetXMLVB.readStringXml(inData, "TRANSTEL");
			inputMap[24] = GetXMLVB.readStringXml(inData, "TRANS_PROVINCE");
			inputMap[25] = GetXMLVB.readStringXml(inData, "TRANS_CITY");
			inputMap[26] = GetXMLVB.readStringXml(inData, "TRANS_AREA");
			inputMap[27] = GetXMLVB.readStringXml(inData, "TRANSADDRESS");
			inputMap[28] = GetXMLVB.readStringXml(inData, "EFFECTDATE");
			inputMap[29] = GetXMLVB.readStringXml(inData, "TRANSTYPE");
			inputMap[30] = GetXMLVB.readStringXml(inData, "REMARK");
			inputMap[31] = GetXMLVB.readStringXml(inData, "FULL_POLICY_NO");
			inputMap[32] = GetXMLVB.readStringXml(inData, "CHECK_DATE");
			inputMap[33] = GetXMLVB.readStringXml(inData, "PAY_DATE");
			inputMap[34] = GetXMLVB.readStringXml(inData, "PAY_TYPE");
			inputMap[35] = GetXMLVB.readStringXml(inData, "TRADENO");
			inputMap[36] = GetXMLVB.readStringXml(inData, "SERVICE_AREA");
			inputMap[37] = GetXMLVB.readStringXml(inData, "SOURCE_CODE");

			log.debug("调用存储过程处理SQL:" + procedure);

			outData = eliteBean.executeWithReturn(procedure, inputMap, "dataSource");
			
			log.debug("调用存储过程处理返回:" + outData);

		} catch(Exception e) {
			log.error("接口处理异常" + e.getMessage());
			//失败返回
			outData= "<?xml version=\"1.0\" encoding=\"UTF-8\"?><PACKET TYPE=\"RESPONSE\" VERSION=\"1.0\"><HEAD><REQUEST_TYPE>P1</REQUEST_TYPE><RESPONSE_CODE>0</RESPONSE_CODE><ERROR_MESSAGE>"+e.getMessage()+"</ERROR_MESSAGE></HEAD></PACKET>";

		}

		log.info("接口处理返回:" + outData);
		return outData;
	}
}